#!/bin/bash 

# Compute the canonicalized name by finding the physical path 
# for the directory we're in and appending the target file.
SCRIPTPATH=$(dirname "$0")

# Check if the user has specified a base dir option on the command line.
# if it is not set the argument will be added with the current working dir as value.
BASEDIR_FOUND=0
for var in "$@"
do
    if [ "$var" == "-d" ]; then 
	BASEDIR_FOUND=1
    else if [ "$var" == "--baseDir" ]; then
        BASEDIR_FOUND=1
    fi
    fi
done

if [ $BASEDIR_FOUND == 0 ]; then
    BASEDIR_ARG="-d \"$(pwd)\""
else
    BASEDIR_ARG=""
fi

# test executable
if test -x "$SCRIPTPATH/../MacOS/itemisCREATE"; then
	SCTEXECUTABLE=$SCRIPTPATH/../MacOS/itemisCREATE
else
    if test -x "$SCRIPTPATH/../MacOS/eclipse"; then
        SCTEXECUTABLE=$SCRIPTPATH/../MacOS/eclipse
    else
        echo "[ERROR] Neither 'SCT' nor 'eclipse' executable found!" 1>&2
        exit -1
    fi
fi


# Call SCT with its headless.ini via this path and forward arguments
# 
#echo "Launching $SCRIPTPATH/../MacOS/SCT --launcher.ini headless.ini $@"
"$SCTEXECUTABLE" --launcher.ini "$SCRIPTPATH/headless.ini" "$@" $BASEDIR_ARG -vmargs -Dorg.eclipse.emf.ecore.plugin.EcorePlugin.doNotLoadResourcesPlugin=true
